package com.example.demo.controller;

import com.example.demo.Utils.MD5Utils;
import com.example.demo.entity.User;
import com.example.demo.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@CrossOrigin
public class UserController {
    @Autowired
    public  UserServiceImpl userService;

    @PostMapping("/login")
    public String login(@RequestBody User unamePassword){
        User user=userService.login(unamePassword.getUsername());
        if (user != null){
            if (user.getPassword().trim().equals(MD5Utils.md5(unamePassword.getPassword()))){
                return "success";
            }
        }
        return "fail";
    }

    @PostMapping("/register")
    public String register(@RequestBody User user){
        userService.register(user);
        return "success";

    }
}
